fix relative install path for updating packages #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When oppm updates a package it searches for any existing file from the package that is still defined in the package install definition. The purpose of the code is then to remove the destination path suffix so as to leave the original relative path used by the user, in case it wasn't simply /usr (default).
gsub is used to remove the install path suffix, but the given string is the installed file path string and thus the regular expression needs to remove the file name from the path. My solution is to include any non / chars from the end of the string. This should leave the relative path root used in the original install.
Note however that this is not a completely safe expectation. If the pkg owner changes the install path completely on an existing repo file, this code would assume gsub would have removed a part of the path that no longer would exist. For this purpose I've added the matches count check. Note also that it is possible that not a single file in the pkg still matches the previous path endings. In this case, /usr would be used and it is possible that the pkg would install twice in two separate paths (in case the user specified a custom install path a previous time). It's rather low risk, but I thought I'd point it out.